LINKER:=ld
COMPLIER:=gcc
AS:=as

OUTPUT:=
LINKER_SCRIPT:=

INCLUDEC:=../include/c/  
INCLUDESYS:=../include/sys/

LIBC:=c
LIBSYS:=sys

LIB_PATH:=../lib/

NULL:=

#$(call auto_make_local_var,prefix_name)
define auto_make_local_var

%.o:COMPILER_OPT:=-o
%.s:COMPILER_OPT:=-S -ffreestanding -fno-toplevel-reorder -nostdinc -fomit-frame-pointer -I $(INCLUDEC) -I $(INCLUDESYS) -fsigned-char -Wall -o

$(eval $1_csrcs:=$(shell find . -name "*.c"))
$(eval $1_asrcs:=$(shell find . -name "*.s"))
$(eval $1_hdrs:=$(shell find . -name "*.h"))
$(eval OUTPUT:=$1)
$(eval LINKER_SCRIPT:=$1.lds)
$(eval $1_objs:=$(patsubst  %.c,%.o, $($1_csrcs)))
$(eval $1_objs+=$(patsubst  %.s,%.o, $($1_asrcs)))
$1_aobjs:=$(patsubst %.c,%.s, $($1_csrcs))
$1_objs:=$(sort $($1_objs))
LINKER_OPT:=-nostdlib -znodefaultlib  -zmuldefs --no-undefined -X -T $(LINKER_SCRIPT) -o $(OUTPUT)  $($1_objs) -static -L ../lib/ -lsys -lc
endef

#$(call make_dependency,prefix_name)
#define make_dependency
#$$($1):$$($1.elf)
#$$($1.elf):$$($1_objs)
#	@echo "elf target is $@"
#	@echo "elf dependency is $^"
#	@echo $(NULL)
#
#$$($1_objs):%.o:%.s
#	@echo "obj target is $@"
#	@echo "obj dependency is $^"
#	@echo "obj COMPILER_OPT is $(COMPILER_OPT)"
#	$(COMPLIER)  $(COMPILER_OPT) $@ $<
#
#$$($1_aobjs):%.s:%.c  $$($1_hdrs)
#	@echo "assemb target is $@"
#	@echo "assemb dependency is $^"
#	@echo "assemb COMPILER_OPT is $(COMPILER_OPT)"
#	$(COMPLIER)  $(COMPILER_OPT) $@ $^
#endef
